import React from "react";
import '../css/Board.css';
import eventEmitter from '../event';

class Board extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            messages:[]
        }
    }

    // mounted
    componentDidMount(){
        eventEmitter.addListener("sendMessageTooBoard",(message)=>{
            console.log(message);
            this.state.messages.push(message);
            this.setState({
                message:this.state.messages
            })
        })
    }

    render() {
        return( 
            <div className="board">
                {
                    this.state.messages.map((element,index)=>{
                        return <div className="message">
                            <h3>{element.content}</h3>
                            <h3>{element.date}</h3>
                        </div>
                    })
                }
            </div>
        )
    }
}

export default Board;